home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 July / macformat52.iso / mac / Shareware Plus / Developers / YAAF v1.0 alpha 1 / (Samples) / Test Programs / TestSingleDialog / main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-16  |  3.0 KB  |  180 lines

  1. /*    main.cpp
  2.  *
  3.  *        This is the actual core which makes this thing fly.
  4.  */
  5.  
  6. #include <string.h>
  7. #include <XApplication.h>
  8. #include <XWindow.h>
  9. #include <XDialog.h>
  10. #include <XStdControls.h>
  11. #include <XStdButtons.h>
  12. #include <XStdScroll.h>
  13. #include <XStdText.h>
  14.  
  15. /************************************************************************/
  16. /*                                                                        */
  17. /*    The test                                                            */
  18. /*                                                                        */
  19. /************************************************************************/
  20.  
  21. /*    MyProc
  22.  *
  23.  *        Handle my procedure
  24.  */
  25.  
  26. static long MyProc(XGDialog *d, void *, long msg, long arg, void *c)
  27. {
  28.     XGStdButton *b;
  29.     XGStdText *t;
  30.     char buffer[4];
  31.     int v;
  32.     
  33.     if (msg == KEventButton) {
  34.         if (arg == 1) {
  35.             d->EndDialog(0);
  36.             return 1;
  37.         } else {
  38.             b = (XGStdButton *)c;
  39.             b->SetValue((b->GetValue()) ? 0 : 1);
  40.         }
  41.     } else if (msg == KEventScroll) {
  42.         XGSScrollEvent *se;
  43.         se = (XGSScrollEvent *)c;
  44.         t = (XGStdText *)(d->FindViewByID(5));
  45.         if (t) {
  46.             v = se->scroll->GetValue();
  47.             
  48.             buffer[0] = (v / 100) + '0';        // cheap atol()
  49.             buffer[1] = ((v / 10) % 10) + '0';
  50.             buffer[2] = (v % 10) + '0';
  51.             buffer[3] = 0;
  52.             
  53.             t->SetText(buffer);
  54.             t->UpdateView();
  55.         }
  56.     }
  57.     return 0;
  58. }
  59.  
  60. /*    DoTestModal
  61.  *
  62.  *        Test my dialog creation/event loop stuff
  63.  */
  64.  
  65. static void DoTestModal(void)
  66. {
  67.     XGDialog::ModalDialog(130,MyProc,NULL);
  68. }
  69.  
  70. /*    DoTestModeless
  71.  *
  72.  *        Test my dialog creation/event loop stuff
  73.  */
  74.  
  75. static void DoTestModeless(void)
  76. {
  77.     XGDialog::Create(130,MyProc,NULL);
  78. }
  79.  
  80. /************************************************************************/
  81. /*                                                                        */
  82. /*    My app                                                                */
  83. /*                                                                        */
  84. /************************************************************************/
  85.  
  86. /*    TMyApp
  87.  *
  88.  *        My application
  89.  */
  90.  
  91. class TMyApp : public XGAppSingleWindow {
  92.     public:
  93.                                 TMyApp();
  94.         virtual                    ~TMyApp();
  95.         long                    ReceiveDispatch(long msg, long arg, void *parg);
  96. };
  97.  
  98. /*    TMyApp::TMyApp
  99.  *
  100.  *        Create this
  101.  */
  102.  
  103. TMyApp::TMyApp()
  104. {
  105.     XGInitStandardControls();
  106. }
  107.  
  108. /*    TMyApp::~TMyApp
  109.  *
  110.  *        Create this
  111.  */
  112.  
  113. TMyApp::~TMyApp()
  114. {
  115.     XGKillStandardControls();
  116. }
  117.     
  118. /*    TMyApp::ReceiveDispatch
  119.  *
  120.  *        Do my test
  121.  */
  122.  
  123. long TMyApp::ReceiveDispatch(long msg, long arg, void *parg)
  124. {
  125.     if (!IsModalWindow()) {
  126.         if (msg == KEventDoMenuCommand) {
  127.             if (arg == 100) {
  128.                 DoTestModal();
  129.                 return 1;
  130.             }
  131.             if (arg == 101) {
  132.                 DoTestModeless();
  133.                 return 1;
  134.             }
  135.         } else if (msg == KEventGetMenuStatus) {
  136.             if ((arg == 101) || (arg == 100)) {
  137.                 ((XGSMenuStatusRecord *)parg)->enable = true;
  138.                 return 1;
  139.             }
  140.         }
  141.     }
  142.         
  143.     return XGAppSingleWindow::ReceiveDispatch(msg,arg,parg);
  144. }
  145.  
  146.  
  147. /************************************************************************/
  148. /*                                                                        */
  149. /*    Main entry point                                                    */
  150. /*                                                                        */
  151. /************************************************************************/
  152.  
  153. /*    StartApplication
  154.  *
  155.  *        This starts up the application
  156.  */
  157.  
  158. XGAppCore *StartApplication(void)
  159. {
  160.     XGAppSingleWindow *aw;
  161.     
  162.     /*
  163.      *    Start application engine
  164.      */
  165.     
  166.     aw = new TMyApp;
  167.     
  168.     /*
  169.      *    Start window
  170.      */
  171.     
  172.     XGWindow::Create(128);
  173.     
  174.     /*
  175.      *    Done. Return
  176.      */
  177.     
  178.     return aw;
  179. }
  180.